package com.linkage.usercenter.utils;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.linkage.common.constant.CommonSysConstant;
import com.linkage.usercenter.pojo.baseDO.TableBaseBO;

import java.util.Arrays;
import java.util.Date;

/**
 * describe:
 *
 * @author shaofeng.cheng
 * @date 2020/04/19
 */
public class TableCommonDataUtil {

    /* *
     * @describe:  类型描述 为数据库表添加修改时间，修改人员
     * @author shaofeng.cheng
     * @title dealCrtUpdTableField
     * @date 2020/4/19 23:29
     * @param [bo, userCode]
     * @return void
     * @version: V1.0
     */
    public static void dealCrtUpdTableField(String userCode, TableBaseBO... bos){
        if(ObjectUtil.isNull(bos)){
            return;
        }
        Arrays.stream(bos).filter( bo -> ObjectUtil.isNotNull(bo)).forEach( bo -> {
            Date date = DateUtil.date();
            if(StrUtil.isBlank(bo.getCreateCode())){
                bo.setCreateCode(userCode);
                bo.setCreateDate(date);
            }
            bo.setUpdateCode(userCode);
            bo.setUpdateDate(date);
        });
    }

    /*  *
     * @describe:  类型描述 人员类型映射机构代码
     * @author shaofeng.cheng
     * @title
     * @date 2020/4/19 23:50
     * @param
     * @return
     * @version: V1.0
     */
    public static String personClassToOrgCode(String personClass) {
        String orgCode = CommonSysConstant.ORG_CODE_POLICE;
        switch (personClass) {
            case CommonSysConstant.PERSON_CLASS_ZERO:
                orgCode = CommonSysConstant.ORG_CODE_MASS;
                break;
            case CommonSysConstant.PERSON_CLASS_ONE:
                orgCode = CommonSysConstant.ORG_CODE_TYPE_5;
                break;
            default:
                break;
        }
        return orgCode;
    }


}
